<%--
  Created by IntelliJ IDEA.
  User: 阿勋
  Date: 2021/7/2
  Time: 14:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <meta charset="utf-8">
    <title>赛事星注册</title>
    <link href="./css/CSS-reset.css" rel="stylesheet"/>
    <link href="./css/jn-style.css" rel="stylesheet"/>
    <link href="./css/login.css" rel="stylesheet"/>

    <script src="./javascript/webConfig.js"></script>
    <script src="./javascript/jquery-1.8.2.min.js"></script>
    <script src="./javascript/jquery.util.js"></script>
    <script src="./javascript/layer.js"></script>
    <script src="./javascript/jsencrypt.min.js"></script>

    <!--[if lt IE 9]>
    <script src="./javascript/html5shiv.min.js"></script>
    ;
    <![endif]-->
</head>

<body class="person-rigister" style="text-align:center">
<div class="jn" style="text-align:left;">
    <div class="person-register-wrapper">
        <header class="clearfix">
            <a href="index.jsp" class="logo"></a>

        </header>
        <section class="person-login-main person-login-main-2020">

            <div class="person-login-box">
                <!--个人-->
                <div class="login-box-content" id="tab0">

                    <div class="login2020-tabs login2020-tabs-new clearfix">
                        <a class="login-2020-tab login-2020-tab1 login-2020-tab-select">
                            <div class="login-2020-reg-title">个人账号注册</div>
                            <div class="login-2020-reg-subtitle">参赛、考试 | 创建考试、问卷</div>
                        </a>
                        <a style="text-decoration:none" href="" class="login-2020-tab login-2020-tab2 ">
                            <div class="login-2020-reg-title">机构账号注册</div>
                            <div class="login-2020-reg-subtitle">创建竞赛、考试、问卷</div>
                        </a>
                    </div>
                    <div class="register-login-line clearfix">
                        <input class="phone" tabindex="1" type="text" value="手机号(11位手机号码)" title="" maxlength="11" size="30" style="color:#b5b5b5;*font-size:14px;">
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>

                    <div class="yanzheng-group  register-login-line jn-clearfix">
                        <div class="clearfix register-yanzheng-group-line">
                            <input class="yanzheng" tabindex="2" type="text" value="验证码" maxlength="6" size="30" style="color:#b5b5b5;*font-size:18px;">
                            <input class="zaicifasong getCode" type="button" value="获取验证码" disabled="disabled">
                        </div>
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>
                    <div class="register-login-line clearfix">
                        <input class="password" tabindex="3" type="text" value="密码(6-20位英文字母、数字、下划线)" maxlength="20" title=""" size="30" style="color:#b5b5b5;*font-size:14px;">
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>

                    <div class="register-login-line2">
                        <input type="button" tabindex="5" class="jn-button login-button" value="立即注册">
                    </div>
                    <div class="login-setting register-login-line2 jn-clearfix">
                        <input id="read1" type="checkbox" checked class="read-agree  register-left-info" tabindex="4">
                        <label for="read1" class="tip">我已阅读并同意</label>
                        <span class="noid"><a href="" target="_blank" class="noid agree">《CNKI赛事星用户注册协议》</a></span>
                    </div>
                    <div class="register-login-line2">

                        <div class="other-three-login  clearfix">
                            <a href=""><img src="./htmlimg/lg10.png" alt=""></a>
                            <a href=""><img src="./htmlimg/lg11.png" alt=""></a>
                            <a href="" style="margin-right:0;"><img src="./htmlimg/lg12.png" alt=""></a>
                        </div>
                    </div>



                </div>
                <!--个人 end-->
                <!--企业-->
                <div class="login-box-content" id="tab1" style="display:none;">
                    <!-- 给下面的class设置为login-right，右侧会出现绿色对勾，设为login-wrong，右侧会出现错误× -->

                    <div class=" register-login-line clearfix">
                        <input class="user-name enterpriseName" tabindex="7" name="user-name" type="text" value="企业名(请输入真实的企业名称)" title="" maxlength="100" size="30" style="color:#b5b5b5;*font-size:14px;">
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>

                    <div class=" register-login-line clearfix">
                        <input class="phone" tabindex="8" type="text" value="手机号(11位手机号码)" title="" maxlength="11" size="30" style="color:#b5b5b5;*font-size:14px;">
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>
                    <div class="yanzheng-group register-login-line jn-clearfix">
                        <div class="clearfix register-yanzheng-group-line">
                            <input class="yanzheng" tabindex="9" type="text" value="验证码" maxlength="6" size="30" style="color:#b5b5b5;*font-size:18px;">
                            <input class="zaicifasong getCode" type="button" value="获取验证码" disabled="disabled">
                        </div>
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>

                    <div class=" register-login-line clearfix">
                        <input class="password" tabindex="10" type="text" value="密码(6-20位英文字母、数字、下划线)" title="" maxlength="20" size="30" style="color:#b5b5b5;*font-size:14px;">
                    </div>
                    <div class="login-alert-black register-login-line2">.</div>
                    <div class="login-setting register-login-line2 jn-clearfix">
                        <input id="read2" type="checkbox" tabindex="11" checked class="read-agree register-left-info">
                        <label for="read2" class="tip">我已阅读并同意</label>
                        <span class="noid agree">《<a href="" target="_blank">赛事星用户注册协议</a>》</span>
                    </div>
                    <div class="register-login-line2">
                        <input type="button" tabindex="12" class="jn-button login-button" value="立即注册">
                    </div>

                    <div class="other-login" style="display:none;">
                        <div class="hezuo jn-clearfix">使用合作网站账号登录</div>
                        <div class="other-three-login" style="width:130px; margin:0 auto;overflow:hidden;">
                            <a href=""><img src="./htmlimg/lg10.png" alt=""></a>
                            <a href=""><img src="./htmlimg/lg11.png" alt=""></a>
                            <a href="" style="margin-right:0;"><img src="./htmlimg/lg12.png" alt=""></a>
                        </div>
                    </div>
                </div>
                <!--企业 end-->
            </div>
        </section>
    </div>
</div>
<input type="hidden" id="hUrl" name="hUrl" value="" />
<a class="login-director-2020" href="login.jsp">已有账号，直接登录 ></a>


<div class="g-footer clearfix" style="margin-top:80px;">
    <div class="g-footer-top-line">《中国学术期刊(光盘版)》电子杂志社有限公司 版权所有</div>
    <div class="g-footer-top-line">京ICP证040431号 网络出版服务许可证 (总)网出证(京)字第271号 京公网安备 11010802020460 号</div>


</div>

<div id="winExistTel" class="user-exist-window phone-exist-window" style="display:none;">
    <div class="user-exist-window-header">
        <div class="title">提示</div>
        <div class="close" style="cursor:pointer;">×</div>
    </div>
    <div class="user-exist-window-body">
        <div class="phone-info">手机号<label id="lblExistTel"></label>已经注册，请直接登录</div><a href="" class="btn-default">登录</a>
    </div>
</div>




<div id="winBindedTel" class="user-exist-window phone-exist-window" style="display:none;">
    <div class="user-exist-window-header">
        <div class="title">提示</div>
        <div class="close" style="cursor:pointer;">×</div>
    </div>
    <div class="user-exist-window-body">
        <div class="phone-info">手机号<label id="lblBindedTel"></label>已经被账号绑定，点击用户名直接登录</div><a href="" class="btn-default" style="cursor:pointer;"><img src="./htmlimg/icon-user.png"> <label id="lblBindedUserName"></label></a>
    </div>
</div>



<script type="text/javascript">

    $().ready(function () {
        $(".close").bind("click", closeWin);

    });

    var enterpriseName = $(".enterpriseName");
    var userName = "";
    var password = $(".password");
    var phone = $(".phone");
    var validateCode = $(".getCode");
    var validCodeText = $(".yanzheng");//输入框
    var userType = 1; //默认为个人用户登录
    var phoneNumState = false; //电话号码格式默认不正确
    var errorMessage = $(".errorMessage");
    var clause = $(".read-agree"); //条款
    var checkboxState = true; //条款默认没有勾选
    var submit = $(".login-button");

    var usernameValue, passwordValue, validcodeValue, tel, instiNameValue; //定义需要提交的变量

    //企业与个人注册切换
    function showTab(num) {
        //for (i = 0; i < 2; i++) {
        //    document.getElementById("tab" + i).style.display = "none";
        //    document.getElementById("id" + i).className = "white";

        //}
        //document.getElementById("tab" + num).style.display = "block";
        //document.getElementById("id" + num).className = "focus";
        //userType = num + 1;
        //layer.closeAll();//避免切换时，layer.tips弹出的错误提示还未消失的问题。


        if (num == 1) {
            window.location.href = "https://saishi.cnki.net/passport/Account/RegisterInstitution";
        }

    }

    //切换验证码
    function switchImage() {

        var vlocation = "sendtelcode";//发送位置
        var idx = 0;
        //if (userType == 2) {
        //    vlocation = "sendtelcode"
        //    idx = 1;
        //}
        //使用这种原生的js，为验证码图片标签赋值比jquery靠谱。
        try {
            document.getElementById("yzm" + idx).src = "https://saishi.cnki.net/passport/api/Captcha/get?w=140&h=50&n=4&vloca=" + vlocation + "&" + Math.random();

        } catch (e) {
            //setTimeout("switchImage()", 1000)
            alert("验证码报错啦！！！");
        }
    }



    //企业名检测
    enterpriseName.focus(function () {
        ChangeTextBlack($(this));
        if ($(this).val() == '企业名(请输入真实的企业名称)') {
            $(this).val("");
        }
        $(this).removeClass("alert-border").parent().removeClass("login-wrong").removeClass("login-right");
        $(this).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");

    })
    enterpriseName.blur(function () {
        var that = this;
        var value = $(this).val();
        var pointer = $(this);//当前事件对象指针
        if (!$.trim(value) || value == "企业名(请输入真实的企业名称)") {
            $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
            $(this).val("企业名(请输入真实的企业名称)");
            ChangeTextGrey($(this));
            //layer.tips('企业名(请输入真实的企业名称)', that, { tips: 2 });
            $(this).parent().next().html('请输入真实的企业名称').removeClass("login-alert-black").addClass("login-alert");
            return;
        }
        else {
            if (value.length >= 2 && value.length <= 100) {
                var reg = new RegExp("^[\u4e00-\u9fa5_a-zA-Z0-9\s《》（）()]{2,100}$"); //汉字、数字、字母、下划线组成的字符串
                var result = reg.test(value);
                if (result) {
                    $.post("https://saishi.cnki.net/passport/api/apiuser/ExistEnterpriseName", {
                        eName: value
                    }, function (data) {
                        //关闭
                        //layer.close(indexLayer);
                        //layer.msg("注册成功")
                        if (data.ErrorCode == "E0020") {//企业名不存在，可以注册
                            pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                            instiNameValue = enterpriseName.val();
                            $(that).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");

                        }
                        else {
                            pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                            //layer.tips('企业名已存在，请重新输入', that);
                            $(that).parent().next().html('企业名已存在，请重新输入').removeClass("login-alert-black").addClass("login-alert");
                        }
                    });

                }
                else {
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    //layer.tips('企业名格式错误，请重新输入', that);
                    $(that).parent().next().html('企业名格式错误，请重新输入').removeClass("login-alert-black").addClass("login-alert");
                }

            }
            else {
                $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                //layer.tips('企业名格式错误，请重新输入', that);
                $(that).parent().next().html('企业名格式错误，请重新输入').removeClass("login-alert-black").addClass("login-alert");

            }
        }
    })



    //修改文本框的样式为黑字，篮筐，蓝底
    function ChangeTextBlack(jqObject) {
        jqObject.css("border", "1px solid #66b2e6").css("background-color", "#f5fbfe").css("color", "#000");

    }
    //修改文本框的样式为灰字，灰筐，白底
    function ChangeTextGrey(jqObject) {
        jqObject.css("border", "1px solid #dadada").css("background-color", "#ffffff").css("color", "#b5b5b5");
    }

    //清楚文本框的样式篮筐
    function ClearTextBorder(jqObject) {
        jqObject.css("border", "");
    }

    //密码检测
    password.focus(function () {
        ChangeTextBlack($(this));
        var that = this;
        $(that).parent().next().html('').removeClass("login-alert").addClass("login-alert-black");
        $(this).removeClass("alert-border").parent().removeClass("login-wrong").removeClass("login-right");
        if ($(this).val() == "密码(6-20位英文字母、数字、下划线)") {
            $(this).val("");
            $(this)[0].type = "password";
            //alert($(this));
            //alert($(this)[0]);

        }
    });

    password.blur(function () {
        var that = this;
        var value = $(this).val();
        var pointer = $(this);//当前事件对象指针
        if (!$.trim($(this).val()) || $(this).val() == "密码(6-20位英文字母、数字、下划线)") {
            $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
            $(this)[0].type = "text";
            $(this).val("密码(6-20位英文字母、数字、下划线)");
            ChangeTextGrey($(this));
            $(this).parent().next().html('请输入密码').removeClass("login-alert-black").addClass("login-alert");
            return;
        }
        else {
            if (value.length < 6) {
                ClearTextBorder(pointer);
                pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                $(that).parent().next().html('密码过短，请输入6-20位字母、数字、下划线').removeClass("login-alert-black").addClass("login-alert");
                return;
            }

            var reg = new RegExp("^[0-9a-zA-Z_]{6,20}$"); //由数字、26个英文字母或者下划线组成的字符串
            var result = reg.test(value);
            if (result) {
                if (IsContinuousDigit(value)) {
                    ClearTextBorder(pointer);
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(that).parent().next().html('为增强密码保密性，请勿使用连续数字').removeClass("login-alert-black").addClass("login-alert");

                }
                else if (RegularCheck(/(\w)\1{2}/, value) == true) {//3个连续的字母或者数字
                    ClearTextBorder(pointer);
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(that).parent().next().html('为增强密码保密性，请勿使用重复字母').removeClass("login-alert-black").addClass("login-alert");
                }
                else {
                    bPassValidate = true;
                    pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                    passwordValue = pointer.val();
                    $(that).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
                }
            }
            else {
                ClearTextBorder(pointer);
                pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                $(that).parent().next().html('密码格式错误，仅支持6-20位字母、数字、下划线').removeClass("login-alert-black").addClass("login-alert");
                //layer.tips('密码格式错误，请重新输入', that);
            }
        }
    });

    var isPopWindow = false;
    //手机号码检测
    phone.focus(function () {
        ChangeTextBlack($(this));
        if ($(this).val() == "手机号(11位手机号码)") {
            $(this).val("");
        }
        $(this).removeClass("alert-border").parent().removeClass("login-wrong").removeClass("login-right");
        $(this).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
    });
    phone.keyup(function () {
        var that = this;
        var value = $(this).val();
        var pointer = $(this);//当前事件对象指针
        var result = value.isMobile();
        if (result && downTime <= 1) {
            //pointer.removeClass("alert-border").parent().removeClass("login-wrong").addClass("login-right");
            //validateCode.eq(userType - 1).removeClass("zaicifasong").addClass("huoquyanzheng").attr("disabled", false);
        }
        else {
            //$(this).addClass("alert-border").parent().addClass("login-wrong");
            validateCode.eq(userType - 1).removeClass("huoquyanzheng").addClass("zaicifasong").attr("disabled", "disabled");
        }
    });
    phone.blur(function () {
        var that = this;
        var value = $(this).val();
        var pointer = $(this);//当前事件对象指针
        if (!$.trim($(this).val()) || $(this).val() == "手机号(11位手机号码)") {
            $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
            $(this).val("手机号(11位手机号码)");
            ChangeTextGrey($(this));
            //layer.tips('请输入手机号码', that);
            $(this).parent().next().html('请输入手机号码').removeClass("login-alert-black").addClass("login-alert");
            return;
        }
        else {
            if ($.trim(value).length == 11) {
                var result = value.isMobile();
                if (result) {
                    phoneNumState = true;
                    //var layeri = layer.load(1, { shade: [0.8, '#393D49'], time: 3000 });
                    $.getJSON("https://saishi.cnki.net/passport/api/apiuser/checktel/" + value, {}, function (data) {
                        //layer.close(layeri);
                        if (data.ErrorCode == "E0020") { //用户名不存在，可以注册
                            pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                            usernameValue = value;
                            $(that).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
                            validateCode.eq(userType - 1).removeClass("zaicifasong").addClass("huoquyanzheng").attr("disabled", false);

                            //手机号文本框 出现绿色通过标记
                            pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                            tel = $(this).val();
                            //validateCode.eq(userType - 1).removeClass("zaicifasong").addClass("huoquyanzheng").attr("disabled", false);
                            $(this).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
                        }
                        else if (data.ErrorCode == "E0048") {
                            ClearTextBorder(pointer);
                            pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                            $(that).parent().next().html('手机号已使用').removeClass("login-alert-black").addClass("login-alert");
                            if (!isPopWindow) {
                                layer.open({
                                    type: 1,
                                    title: false,
                                    skin: 'layui-layer-demo', //样式类名
                                    closeBtn: 0, //不显示关闭按钮
                                    anim: 2,
                                    area: ['498px', '227px'],
                                    shadeClose: false, //开启遮罩关闭
                                    content: $('#winBindedTel')
                                });
                                $("#lblBindedTel").html(value);
                                $("#lblBindedUserName").html(data.UserName);
                                $('#winBindedTel').show();
                                isPopWindow = true;
                            }
                        }
                        else if (data.ErrorCode == "E0021") {
                            if (!isPopWindow) {
                                //页面层-佟丽娅
                                layer.open({
                                    type: 1,
                                    title: false,
                                    skin: 'layui-layer-demo', //样式类名
                                    closeBtn: 0, //不显示关闭按钮
                                    anim: 2,
                                    area: ['498px', '227px'],
                                    shadeClose: false, //开启遮罩关闭
                                    content: $('#winExistTel')
                                });
                                $("#lblExistTel").html(value);
                                $('#winExistTel').show();
                                isPopWindow = true;
                            }

                            ClearTextBorder(pointer);
                            pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                            $(that).parent().next().html('手机号已存在').removeClass("login-alert-black").addClass("login-alert");
                        }
                        else {
                            layer.alert(data.ErrorMessage);
                        }
                    });

                    //pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                    //tel = $(this).val();
                    ////validateCode.eq(userType - 1).removeClass("zaicifasong").addClass("huoquyanzheng").attr("disabled", false);
                    //$(this).parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
                }
                else {
                    phoneNumState = false;
                    ClearTextBorder(pointer);
                    $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    //validateCode.eq(userType - 1).removeClass("huoquyanzheng").addClass("zaicifasong").attr("disabled", "disabled");
                    $(this).parent().next().html('手机号码格式错误，请重新输入').removeClass("login-alert-black").addClass("login-alert");
                }
            }
            else {
                phoneNumState = false;
                ClearTextBorder(pointer);
                $(this).addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                //validateCode.eq(userType - 1).removeClass("huoquyanzheng").addClass("zaicifasong").attr("disabled", "disabled");
                $(this).parent().next().html('请输入手机号(11位手机号码)').removeClass("login-alert-black").addClass("login-alert");

            }
        }
    });

    function closeWin() {
        layer.closeAll();
        isPopWindow = false;

    }
    var idxSend = 0;
    //60秒倒计时
    var downTime = 1;
    var pointercs;
    var thatcs;
    //获取验证码
    validateCode.click(function () {
        if (downTime > 1) {
            layer.msg("不能频繁获取，请稍后");
            return;
        }
        var that = this;
        var pointer = $(this);
        thatcs = that;
        pointercs = pointer;
        var vctype = "registerperson";//默认为个人用户
        if (userType == 2) {
            vctype = "registerenterprise"; //企业用户
        }
        closeWin();

        //自定页
        idxSend = layer.open({
            type: 1,
            skin: 'layui-layer-demo', //样式类名
            title: false,
            area: ['490px', '252px'],
            closeBtn: 0, //不显示关闭按钮
            anim: 2,
            success: function (layero, index) {
                switchImage();
            },
            shadeClose: true, //开启遮罩关闭
            content: '<div class="yanzheng-window">'
                + '<div class="yanzheng-top" style="height:46px;">'
                + '<div class="title">图形验证码</div>'
                + '<a href="" onclick="closeWin()" class="close">×</a>'
                + '</div>'
                + '<div class="yanzheng-body">'
                + '<div class="yanzheng-body-line clearfix">'
                + '<input type="text" class="yanzheng-input"  maxlength="4" >'
                + '<img  id="yzm0" onclick="switchImage()" alt="" class="yanzheng-img">'
                + '<a href="" onclick="switchImage()" class="yanzheng-fresh"></a>'
                + '</div>'
                + '<div class="yanzheng-button-line clearfix">'
                + '<a href="" onclick="closeWin()"  class="u-btn cancel">取消</a>'
                + '<a href="" onclick="fnSendTel()" class="u-btn confirm">确定</a>'
                + '</div>'
                + '</div>'
                + '</div>'
        });

        $(".yanzheng-window").parent().css("overflow", "hidden");//修复弹窗的水平及垂直滚动条


    });

    function fnSendTel() {
        if (phoneNumState) {
            var domThis = validateCode.eq(userType - 1);
            var txtYanZheng = $(".yanzheng-input").eq(userType - 1).val();
            var vctype = "registerperson";//默认为个人用户
            if (userType == 2) {
                vctype = "registerenterprise"; //企业用户
            }

            if (txtYanZheng == "") {
                layer.alert("请输入图片验证码", { icon: 2 });
                return;
            }
            $.get("https://saishi.cnki.net/passport/api/apiuser/sendtelvalicode/" + phone.eq(userType - 1).val() + "?yzcode=" + txtYanZheng + "&vctype=" + vctype, null, function (data) {
                if (data.ErrorCode == "E0028") {
                    $(domThis).removeClass("huoquyanzheng").addClass("zaicifasong").val(60 + "s重新发送").attr("disabled", "disabled");
                    var timer = setTimeout(countDown, 1000);
                    closeWin();
                }
                else if (data.ErrorCode == "E0048") {
                    //被绑定
                    if (isPopWindow) {
                        closeWin();
                    }
                    layer.open({
                        type: 1,
                        title: false,
                        skin: 'layui-layer-demo', //样式类名
                        closeBtn: 0, //不显示关闭按钮
                        anim: 2,
                        area: ['498px', '227px'],
                        shadeClose: false, //开启遮罩关闭
                        content: $('#winBindedTel')
                    });
                    $("#lblBindedTel").html(value);
                    $("#lblBindedUserName").html(data.UserName);
                    $('#winBindedTel').show();
                    isPopWindow = true;

                }
                else if (data.ErrorCode == "E0021") {
                    if (isPopWindow) {
                        closeWin();
                    }
                    //用户名存在
                    layer.open({
                        type: 1,
                        title: false,
                        skin: 'layui-layer-demo', //样式类名
                        closeBtn: 0, //不显示关闭按钮
                        anim: 2,
                        area: ['498px', '227px'],
                        shadeClose: false, //开启遮罩关闭
                        content: $('#winExistTel')
                    });
                    $("#lblExistTel").html(value);
                    $('#winExistTel').show();
                    isPopWindow = true;

                    ClearTextBorder(pointer);
                    pointercs.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(thatcs).parent().next().html('手机号已存在').removeClass("login-alert-black").addClass("login-alert");
                }
                else if (data.ErrorCode == "E0036" || data.ErrorCode == "E0037") {
                    layer.confirm(data.ErrorMessage, {
                        btn: ['继续', '取消'] //按钮
                    }, function () {
                        layer.closeAll('dialog'); //关闭信息框
                        $.get("https://saishi.cnki.net/passport/api/apiuser/sendtelvalicode/" + phone.eq(userType - 1).val() + "?IsContinue=true&vctype=" + vctype, null, function (data) {
                            if (data.ErrorCode == "E0028") {
                                $(domThis).removeClass("huoquyanzheng").addClass("zaicifasong").val(60 + "s重新发送").attr("disabled", "disabled");
                                var timer = setTimeout(countDown, 1000);
                            } else {
                                layer.alert(data.ErrorMessage, { icon: 2 });
                            }
                            //errorMessage.eq(userType - 1).css("display", "block").html(data.ErrorMessage);
                        })
                    }, function () {
                        layer.closeAll('loading');
                        return;
                    });
                } else if (data.ErrorCode == "-3") {
                    layer.alert(data.ErrorMessage, { icon: 2 });
                } else {
                    layer.alert(data.ErrorMessage, { icon: 2 });//layer.alert('发送短信时异常，请联系管理员', { icon: 2 });
                }
                //errorMessage.eq(userType - 1).css("display", "block").html(data.ErrorMessage);
            })
        };
    }

    function countDown() {
        pointercs.val(60 - downTime + "s重新发送");
        downTime++;
        if (downTime == 61) {
            validateCode.removeClass("zaicifasong").addClass("huoquyanzheng").val("重新发送");
        }
        if (downTime <= 60) {
            setTimeout(arguments.callee, 1000);
        }
        else {
            downTime = 1;
            validateCode.attr("disabled", false)
        }
    };




    //获取验证码值
    validateCode.siblings("input").focus(function () {
        ChangeTextBlack($(this));
        if ($(this).val() == "验证码") {
            $(this).val("");
        }
        $(this).removeClass("alert-border").parent().parent().removeClass("login-wrong").removeClass("login-right");
        $(this).parent().parent().next().html('.').removeClass("login-alert").addClass("login-alert-black");
    }).blur(function () {
        var that = this;
        if (!$.trim($(this).val()) || $(this).val() == "验证码") {
            $(this).addClass("alert-border").parent().parent().addClass("login-wrong").removeClass("login-right");
            $(this).val("验证码");
            ChangeTextGrey($(this));
            //layer.tips('请输入验证码', that);
            $(this).parent().parent().next().html('请输入验证码').removeClass("login-alert-black").addClass("login-alert");
            return;
        }
        var reg = /^\d{6}$/; //6个字母数字
        var result = reg.test($(this).val());
        if (result) {
            validcodeValue = $(this).val();
            $(this).addClass("alert-border").parent().parent().addClass("login-right").removeClass("login-wrong");
        }
        else {
            ClearTextBorder($(this));
            $(this).addClass("alert-border").parent().parent().addClass("login-wrong").removeClass("login-right");
            //layer.tips('请输入6位数字验证码', that);
            $(this).parent().parent().next().html('请输入6位数字验证码').removeClass("login-alert-black").addClass("login-alert");

        }
    });


    //验证码输入框
    validCodeText.focus(function () {
        ChangeTextBlack($(this));
        if ($(this).val() == "验证码") {
            $(this).val("");
        }

    });
    validCodeText.blur(function () {
        if (!$.trim($(this).val()) || $(this).val() == "验证码") {
            $(this).addClass("alert-border").parent().parent().removeClass("login-right").addClass("login-wrong");
            $(this).val("验证码");
            ChangeTextGrey($(this));
            $(this).parent().next().html('请输入验证码').removeClass("login-alert-black").addClass("login-alert");
            //layer.tips('请输入验证码', that);
            return;
        }

    });

    //获取同意条款值
    clause.click(function () {
        checkboxState = Boolean($(".read-agree").eq(userType - 1).attr("checked"));//获取同意条款值
    })


    var jsPublicKey = "-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8iKgnXm7hTxEr9FcZtBk/xbL8JwSeGpgpGMdd7TgBIARcWXhYeGRP428QYb8//Buls3ZLJAbc4Z8HxFP5yvVMksQEBkR5NyN2Jx3i83jUDX/STLy9ZhCBskNBt1zqtTRw4eEjvmsP5iZ4PyQUXUttyY2Mbjb9AZl87lTlrDCRQwIDAQAB-----END PUBLIC KEY-----";
    //注册提交
    submit.click(function () {

        var isPassValid = true;

        if (userType == 2) {
            var validResult5 = ValidateEnterpriseName(enterpriseName.eq(0), false);
            if (validResult5 == false) {
                isPassValid = false;
            }
            //return;
        }


        var validResult3 = ValidateTel(phone.eq(userType - 1));
        if (validResult3 == false) {
            isPassValid = false;
        }

        var validResult2 = ValidatePassword(password.eq(userType - 1));
        if (validResult2 == false) {
            isPassValid = false;
        }
        //return;

        //return;
        var validResult4 = ValidateShortCode(validateCode.eq(userType - 1), validCodeText.eq(userType - 1).val());
        if (validResult4 == false) {
            isPassValid = false;
        }
        if (isPassValid == false) {
            return false;
        }


        var prompt = "";

        if (tel == undefined || tel == "") {
            prompt = "手机号不能为空";
            if (tel == undefined)
                prompt = "手机号格式不正确";
            layer.msg(prompt);
            return;
        }

        if (validcodeValue == undefined || validcodeValue == "") {
            prompt = "短信验证码不能为空";
            if (validcodeValue == undefined)
                prompt = "验证码格式不正确";
            layer.msg(prompt);
            return;
        }

        if (passwordValue == undefined || passwordValue == "") {
            prompt = "密码不能为空";
            if (passwordValue == undefined)
                prompt = "密码格式不正确";
            layer.msg(prompt);
            return;
        }

        if (IsIllegalChar(passwordValue)) {
            prompt = "密码包含非法字符，请修改";
            layer.msg(prompt);
            return;
        }


        checkboxState = Boolean($(".read-agree").eq(userType - 1).attr("checked"));//获取同意条款值
        if (checkboxState == undefined || !checkboxState) {
            layer.msg('请先确认阅读了《CNKI赛事星用户注册协议》');
            return;
        }


        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(jsPublicKey);

        var gourl = $("#hUrl").val();
        if (userType == 1) {
            if (usernameValue && passwordValue && validcodeValue && tel && checkboxState) {
                var indexLayer = layer.load(2, { shade: [0.6, '#000'] });; //换了种风格
                $.post("https://saishi.cnki.net/passport/api/apiuser/registermobile", {
                    username: usernameValue,
                    password: encrypt.encrypt(passwordValue),
                    validcode: validcodeValue,
                    tel: tel,
                    usertype: userType
                }, function (data) {
                    //关闭
                    if (data.ErrorCode == "E0023") {
                        layer.msg("注册成功")
                        //window.location.href = "https://saishi.cnki.net/passport/Account/RegisterSuccess?retUrl=" + gourl;//注册成功，设置昵称页面
                        window.location.href = gourl;//注册成功，直接返回
                    }
                    else if (data.ErrorCode == "E0024") {
                        if (data.ErrorMessage.indexOf("验证码不正确") >= 0) {
                            layer.msg("短信验证码错误");
                        }
                        else {
                            layer.msg(data.ErrorMessage);//"注册失败，" +
                        }
                        layer.close(indexLayer);

                    }
                    else {
                        layer.msg(data.ErrorMessage);//"注册失败，" +
                        layer.close(indexLayer);
                    }
                })
            }

        }
        if (userType == 2) {

            if (instiNameValue == undefined || instiNameValue == "") {
                layer.msg('机构名称不能为空');
                return;
            }

            if (usernameValue && passwordValue && validcodeValue && tel && instiNameValue && checkboxState) {
                var indexLayer = layer.load(2, { shade: [0.6, '#000'] });; //换了种风格
                $.post("https://saishi.cnki.net/passport/api/apiuser/RegisterInstitution", {
                    username: usernameValue,
                    password: passwordValue,
                    validcode: validcodeValue,
                    tel: tel,
                    usertype: userType,
                    instiName: instiNameValue
                }, function (data) {
                    //关闭
                    //layer.close(indexLayer);
                    layer.msg("注册成功");
                    if (data.ErrorCode == "E0023") {
                        //window.location.href = "https://saishi.cnki.net/passport/Account/RegisterSuccess?retUrl=" + gourl;
                        window.location.href = DomainUrlHelper.InstituCenterAction + "Institutioninfo/Attestation?type=Company&step=1&retUrl=" + gourl;
                    }
                    else {
                        layer.msg("注册失败，" + data.ErrorMessage);
                        layer.close(indexLayer);
                        //alert(data.ErrorMessage);
                    }
                })
            }
        }
    });

    //是否包含非法字符
    function IsIllegalChar(inputValue) {
        var bHaveBadChar = false;
        if (inputValue.indexOf('<') >= 0) {
            bHaveBadChar = true;
        }

        if (inputValue.indexOf('</') >= 0) {
            bHaveBadChar = true;
        }
        //if (inputValue.indexOf(' ') >= 0 || inputValue.indexOf('　') >= 0) {
        //    bHaveBadChar = true;
        //}
        if (/[@#\$%\^&\*<>/-]+/g.test(inputValue)) {
            bHaveBadChar = true;
        }
        return bHaveBadChar;
    }

    //是否是连续数字
    function IsContinuousDigit(val) {
        var iscontinuous = false;
        var s = "012345678901234";
        for (var i = 0; i < 10; i++) {
            if (val.indexOf(s.substring(i, i + 5)) > 0) {

                iscontinuous = true;
                break;
            }
        }
        return iscontinuous;
    }

    //验证密码
    function ValidatePassword(jqObject) {
        var bPassValidate = false;
        if (jqObject) {
            //验证长度
            //是否含有特殊字符
            //验证字符范围是否合法
            var value = jqObject.val();
            var that = jqObject;
            var pointer = jqObject;//$(this);//当前事件对象指针
            if (!$.trim(value) || value == "密码(6-20位英文字母、数字、下划线)") {
                pointer.addClass("alert-border").parent().removeClass("login-right").addClass("login-wrong");
                pointer[0].type = "text";
                pointer.val("密码(6-20位英文字母、数字、下划线)");
                //layer.tips('请输入密码', that);
                $(that).parent().next().html('请输入密码').removeClass("login-alert-black").addClass("login-alert");

                bPassValidate = false;
            }
            else {
                if (value.length < 6) {
                    bPassValidate = false;
                    ClearTextBorder(pointer);
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(that).parent().next().html('密码过短，请输入6-20位字母、数字、下划线').removeClass("login-alert-black").addClass("login-alert");
                    return;
                }
                if (value.length > 20) {
                    bPassValidate = false;
                    ClearTextBorder(pointer);
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(that).parent().next().html('密码过长，请输入6-20位字母、数字、下划线').removeClass("login-alert-black").addClass("login-alert");
                    return;
                }

                var reg = new RegExp("^[0-9a-zA-Z_]{6,20}$"); //由数字、26个英文字母或者下划线组成的字符串
                var result = reg.test(value);
                if (result) {
                    if (IsContinuousDigit(value)) {
                        bPassValidate = false;
                        pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                        $(that).parent().next().html('为增强密码保密性，请勿使用连续数字').removeClass("login-alert-black").addClass("login-alert");

                    }
                    else if (RegularCheck(/(\w)\1{2}/, value) == true) {//3个连续的字母或者数字
                        bPassValidate = false;
                        pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                        $(that).parent().next().html('为增强密码保密性，请勿使用重复字母').removeClass("login-alert-black").addClass("login-alert");
                    }
                    else {
                        bPassValidate = true;
                        pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                        passwordValue = pointer.val();

                    }
                }
                else {
                    bPassValidate = false;
                    pointer.addClass("alert-border").parent().addClass("login-wrong").removeClass("login-right");
                    $(that).parent().next().html('密码格式错误，仅支持6-20位字母、数字、下划线').removeClass("login-alert-black").addClass("login-alert");
                }
            }
        }
        else {
            bPassValidate = false;
        }
        return bPassValidate;
    }

    function ValidateTel(jqObject) {
        var bPassValidate = false;
        if (jqObject) {
            //验证长度
            //是否含有特殊字符
            //验证字符范围是否合法
            var value = jqObject.val();
            var that = jqObject;
            var pointer = jqObject;//$(this);//当前事件对象指针
            if (!$.trim(value) || value == "手机号(11位手机号码)") {
                pointer.addClass("alert-border").parent().removeClass("login-right").addClass("login-wrong");
                pointer[0].type = "text";
                pointer.val("手机号(11位手机号码)");
                //layer.tips('请输入密码', that);
                $(that).parent().next().html('请输入手机号').removeClass("login-alert-black").addClass("login-alert");

                bPassValidate = false;
            }
            else {
                var result = value.isMobile();
                if (result) {
                    bPassValidate = true;
                    tel = value;
                    $(this).removeClass("alert-border").parent().removeClass("login-wrong").addClass("login-right");
                }
                else {
                    bPassValidate = false;
                    pointer.addClass("alert-border").parent().removeClass("login-right").addClass("login-wrong");
                    $(that).parent().next().html('请输入正确的手机号码').removeClass("login-alert-black").addClass("login-alert");
                }


                if (result && downTime <= 1) {
                    pointer.removeClass("alert-border").parent().removeClass("login-wrong").addClass("login-right");
                }
                else {
                    validateCode.eq(userType - 1).removeClass("huoquyanzheng").addClass("zaicifasong").attr("disabled", "disabled");
                }
            }
        }
        else {
            bPassValidate = false;
        }
        return bPassValidate;
    }

    function ValidateShortCode(jqObject, val) {
        var bPassValidate = false;
        if (jqObject) {
            //验证长度
            //是否含有特殊字符
            //验证字符范围是否合法
            var value = val;//jqObject.val();
            var that = jqObject;
            var pointer = jqObject;//$(this);//当前事件对象指针
            if (!$.trim(value) || value == "验证码") {
                pointer.addClass("alert-border").parent().parent().removeClass("login-right").addClass("login-wrong");
                pointer[0].type = "text";
                pointer.val("验证码");
                //layer.tips('请输入密码', that);
                $(that).parent().parent().next().html('请输入验证码').removeClass("login-alert-black").addClass("login-alert");
                bPassValidate = false;
            }
            else {
                var reg = /^\d{6}$/ //6位数字验证码
                var result = reg.test(value);
                if (value.length != 6) {
                    bPassValidate = false;
                    //layer.tips('请输入6位数字格式的验证码', that);
                    $(that).addClass("alert-border").parent().parent().removeClass("login-right").addClass("login-wrong");
                    $(that).parent().parent().next().html('请输入6位数字验证码').removeClass("login-alert-black").addClass("login-alert");
                }
                else {
                    if (result) {
                        validcodeValue = value;
                        bPassValidate = true;
                        $(that).removeClass("alert-border").parent().parent().addClass("login-right").removeClass("login-wrong");
                    }
                    else {
                        $(that).addClass("alert-border").parent().parent().removeClass("login-right").addClass("login-wrong");
                        //layer.tips('请输入6位数字格式的验证码', that);
                        $(that).parent().parent().next().html('请输入6位数字验证码').removeClass("login-alert-black").addClass("login-alert");
                        bPassValidate = false;
                    }
                }
            }
        }
        else {
            bPassValidate = false;
        }
        return bPassValidate;
    }

    function ValidateEnterpriseName(jqObject, async) {
        async = async == undefined ? true : false;//默认是异步
        var bPassValidate = false;
        if (jqObject) {
            //验证长度
            //是否含有特殊字符
            //验证字符范围是否合法
            var value = jqObject.val();
            var that = jqObject;
            var pointer = jqObject;//$(this);//当前事件对象指针

            if (!$.trim(value) || value == "企业名(请输入真实的企业名称)") {
                pointer.addClass("alert-border").parent().addClass("login-wrong");
                pointer.val("企业名(请输入真实的企业名称)");
                //layer.tips('企业名(请输入真实的企业名称)', that, { tips: 2 });
                $(that).parent().next().html('请输入真实的企业名称').removeClass("login-alert-black").addClass("login-alert");
                bPassValidate = false;
                return bPassValidate;
            }
            else {
                if (value.length >= 2 && value.length <= 100) {
                    var reg = new RegExp("^[\u4e00-\u9fa5_a-zA-Z0-9\s《》（）()]{2,100}$"); //汉字、数字、字母、下划线组成的字符串
                    var result = reg.test(value);
                    if (result) {
                        $.ajax({
                            url: "https://saishi.cnki.net/passport/api/apiuser/ExistEnterpriseName",
                            data: { eName: value },
                            async: async,
                            type: "POST",
                            success: function (data) {
                                if (data.ErrorCode == "E0020") {//企业名不存在，可以注册
                                    pointer.removeClass("alert-border").parent().addClass("login-right").removeClass("login-wrong");
                                    instiNameValue = enterpriseName.val();
                                    bPassValidate = true;
                                }
                                else {
                                    pointer.addClass("alert-border").parent().addClass("login-wrong");
                                    $(that).parent().next().html('企业名已存在，请重新输入').removeClass("login-alert-black").addClass("login-alert");

                                    bPassValidate = false;
                                }
                            }
                        });

                    }
                    else {
                        $(that).parent().next().html('企业名格式错误，请重新输入').removeClass("login-alert-black").addClass("login-alert");
                        bPassValidate = false;
                    }

                }
                else {
                    $(this).addClass("alert-border").parent().addClass("login-wrong");
                    $(that).parent().next().html('企业名格式错误，请重新输入').removeClass("login-alert-black").addClass("login-alert");
                    bPassValidate = false;
                }
            }

        }
        else {
            bPassValidate = false;
        }
        return bPassValidate;
    }

    //判断字符串是否是符合给定的正则规则
    function RegularCheck(reg, str) {
        if (reg && str) {
            if (reg.test(str)) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
</script>
</body>
</html>

